package cn.tl.base.service.impl;

import cn.tl.base.mapper.BaseMapper;
import cn.tl.base.query.BaseQuery;
import cn.tl.base.service.IBaseService;

import cn.tl.org.utils.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findById(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public QueryResult<T> queryPage(BaseQuery query) {
        Long count = baseMapper.count(query);
        List<T> data = baseMapper.data(query);
        return new QueryResult<>(count,data);
    }
}
